package com.aqie.security.demo.security;

import com.aqie.security.demo.dto.User;
import com.aqie.security.demo.service.UserServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * @Function:
 * @Author: aqie
 * @Date: 2019/4/5 11:01
 */
@Component
@Slf4j
public class MyUserDetailsService implements UserDetailsService{
    @Autowired
    private UserServiceImpl userService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // 1. 根据用户名查找用户信息
        // 2. 根据查找到用户信息判断用户是否被冻结(七个参数)
        // 3. 使用实体类实现 UserDetails 接口
        User user = userService.findUserByUsername(username);
        return user;
    }
}
